<template>
    <el-dialog title="修改密码" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" label-width="90px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="账号名称" prop="nickname">
              <el-input v-model="nickname" disabled placeholder="请输入用户昵称" />
            </el-form-item>
          </el-col>
        <el-col :span="24">
            <el-form-item label="原密码" prop="oldPassword" verify>
              <el-input v-model="form.oldPassword" placeholder="请输入用户密码" type="password" show-password />
            </el-form-item>
          </el-col>
        <el-col :span="24">
            <el-form-item label="新密码" prop="newPassword" agpass verify>
               <el-input type="password" v-model="form.newPassword" placeholder="请输入密码" show-password></el-input>
            </el-form-item>
          </el-col>
        <el-col :span="24">
            <el-form-item label="确认密码" prop="rePassword" :verify="verifypassword" :watch="form.password">
              <el-input type="password" v-model="form.rePassword" placeholder="请再次输入密码" show-password ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-preventReClick type="primary" @click="submitForm">确 定</el-button>
        <el-button v-preventReClick @click="open = false">取 消</el-button>
      </div>
    </el-dialog>
</template>
<script>
import {
 updateUserProfilePassword
} from "@/api/common/user";
export default {
data(){
 return{
    form:{},
    open:false,
    nickname:''
 }
},
methods:{
    submitForm(){
        let newform = JSON.parse(JSON.stringify(this.form))
         this.$refs.form.validate(valid => {
              if (valid) {
                delete newform.rePasswordt
                updateUserProfilePassword(newform).then(res =>{
                  this.$modal.msgSuccess(res.msg || '重置密码成功');
                  this.open = false
                })
              }
         })
    },
    init(){
        this.open = true
    },
    verifypassword(rule, val, callback) {
            if (val) {
                if (val !== this.form.newPassword) callback(Error('两次输入密码不一致!'));
                else callback();
            } else {
                callback();
            }
    },
},
created(){}
}
</script>
<style scoped>
</style>